;define(function (require) {
	'use strict';
	var d3=require('d3');
	var $=require('jquery');
	var logs=require('plugin/logs');

	function app(){}
	app.prototype={
		init:function(){
			logs.log('loaded.');

			var _nav=require('plugin/nav');
			var nav=new _nav('#navbox','#navpoint');
			nav.run();

			var _Gauge=require('plugin/gauge');

			var c1={
				borderColor:'#D6DFEF',
        innerBorderColor:'#EBF4FA',
        arrowColor:'#427EC9',
        startColor:'#6A9AD7',
        endColor:'#A1D2F0',
        img:{
        	width:28,
        	height:50,
        	src:'asset/img/icon1.png'
        },
        title:'地区生产总值增速'
			};
			var chart1=new _Gauge('#chart-1',9.5, c1);

			var c2={
				borderColor:'#F5E6CD',
        innerBorderColor:'#FAE5C7',
        arrowColor:'#E78F00',
        startColor:'#F09100',
        endColor:'#EAC400',
        waveColor:'#EA9F40',
        img:{
        	width:43,
        	height:27,
        	src:'asset/img/icon2.png'
        },
        title:'一般公共预算增速'
			};
			var chart2=new _Gauge('#chart-2',15.0, c2);

			var c3={
				borderColor:'#CBE7F5',
        innerBorderColor:'#D1E9F6',
        arrowColor:'#00A8E0',
        startColor:'#00A8E0',
        endColor:'#72CD2C',
        waveColor:'#72CD2C',
        img:{
        	width:50,
        	height:56,
        	src:'asset/img/icon3.png'
        },
        title:'固定资产投资额增速'
			};
			var chart3=new _Gauge('#chart-3',13.3, c3);

			var c4={
				borderColor:'#F5E7E4',
        innerBorderColor:'#FDD0BB',
        arrowColor:'#E85800',
        startColor:'#E85800',
        endColor:'#F48C70',
        waveColor:'#E85800',
        img:{
        	width:27,
        	height:38,
        	src:'asset/img/icon4.png'
        },
        title:'社会消费品零售总额'
			};
			var chart4=new _Gauge('#chart-4',9.5, c4);
			var c5={
				borderColor:'#E0EFEB',
        innerBorderColor:'#CDEEE7',
        arrowColor:'#009B7F',
        startColor:'#009B7F',
        endColor:'#2EB5E5',
        waveColor:'#2EB5E5',
        img:{
        	width:48,
        	height:36,
        	src:'asset/img/icon5.png'
        },
        title:'进出口总值'
			};
			var chart5=new _Gauge('#chart-5',-2.9,c5);

			var gauges=[chart1,chart2,chart3,chart4,chart5];
			function updateGauges(gauges)
			{
				for(var i=0;i<5;i++)
				{
					var value = getRandomValue();
					gauges[i].update(value);
				}
			}
			
			function getRandomValue()
			{
				var overflow = 0; //10;
				return 0 - overflow + (100 - 0 + overflow*2) *  Math.random();
			}
			setInterval(function(){
				//随机数
				//updateGauges(gauges);
			}, 10000);


			var _timeline=require('plugin/timeline');
			var timer=new _timeline('#timelinebox');
			timer.init({
				startyear:2014,
				startmonth:10,
				endyear:2015,
				endmonth:10,
				step:10,
				interval:1500,
				callback:function(){
					logs.log(this);
					updateGauges(gauges);
				},
				prevbtn:null,
				nextbtn:null,
				idx:7
			});

			var subcharts=[
				['税收占一般公共预算收入比重',6.7],
				['规模以上工业增加值',8.2],
				['规模以上工业总产值',3.4],
				['工业应税销售收入',6.5],
				['服务业应税销售收入',4.8],
				['全社会用电量',6.7],
				['实际到账注册外资',8.2],
				['新批协议利用外资',3.2],
				['本外币存款余额',6.8],
				['固定资产投资额',8.2]
			];
			$('.minichart').each(function(i){
				var c=c1;
				if(i==5){
					c=c2;
				}else if(i==6){
					c=c3;
				}else if(i==8){
					c=c5
				}else if(i==9){
					c=c4
				}
				c.img=null;
				c.title=subcharts[i][0];
				c.textVertPosition=0.5;
				$(this).attr('id','subchart-'+(i+1));
				var chart=new _Gauge('#subchart-'+(i+1),subcharts[i][1],c);
			});

			var echart=require('echarts');
			var themetw=require('plugin/themetw')
			var option = {
			    tooltip : {
			        trigger: 'axis'
			    },
			    legend: {
			    		show:false,
			        data:['总量']
			    },
			    toolbox: {
			        show : false
			    },
			    calculable : true,
			    xAxis : [
			        {
			            type : 'category',
			            data : ['崇川区','港闸区','开发区','通州区','海安县','如东县','启东市','如皋市','海门市']
			        }
			    ],
			    yAxis : [
			        {
			            type : 'value'
			        }
			    ],
			    series : [
			        {
			            name:'总量',
			            type:'bar',
			            data:[194.75, 132.60, 202.08, 274.51, 239.33, 223.56, 246.39, 219.50, 243.89],
			            markPoint : {
			                data : [
			                    {type : 'max', name: '最高'},
			                    {type : 'min', name: '最低'}
			                ]
			            },
			            markLine : {
			                data : [
			                    {type : 'average', name: '平均值'}
			                ]
			            },
			            itemStyle:{
			            	normal:{
			            		color:'#72BB59',
			            		barBorderRadius:0,
			            		barBorderWidth:0,
			            		label:{
			            			show:true,
			            			position:'top'
			            		}
			            	}
			            },
			            barWidth: 15
			        }
			    ]
			};

			var chartBar = echarts.init(document.getElementById('descchart'), themetw);
			chartBar.setOption(option);
		}
	};
	return app;
});